﻿
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Display;
using Windows.Graphics.Imaging;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.System;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Shapes;

// https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x804 上介绍了“空白页”项模板

namespace pintu
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class MainPage : Page
    {
        bool isremove = false;
        string formmat = ".jpg";
        Popup pop = new Popup() { Width = 305, Height = 360 };
        Popup txtpop = new Popup() { Width = 305, Height = 360 };
        public List<double> fontsizelist = new List<double>();
        public MainPage()
        {
            this.InitializeComponent();
            getFontList();
            this.DataContext = this;
            Getcolorlist();
            Getfontsizelist();

        }
        private void Getfontsizelist()
        {
            fontsizelist.Add(8);
            fontsizelist.Add(10);
            fontsizelist.Add(12);
            fontsizelist.Add(14);
            fontsizelist.Add(16);
            fontsizelist.Add(18);
            fontsizelist.Add(20);
            fontsizelist.Add(22);
            fontsizelist.Add(24);
            fontsizelist.Add(25);
            fontsizelist.Add(30);
            fontsizelist.Add(32);
            fontsizelist.Add(36);
            fontsizelist.Add(60);
            FontsizeListBox.ItemsSource = fontsizelist;
        }
        private void Grid_DragOver(object sender, DragEventArgs e)
        {
            if(App.isrectange)
            {
                return;
            }
            e.AcceptedOperation = DataPackageOperation.Copy;
        }
        private async void Grid_Drop(object sender, DragEventArgs e)
        {
            if(App.isrectange)
            {
                return;
            }
            if (ismovetext)
            {
                string text = await e.DataView.GetTextAsync();

                TextBlock tb = new TextBlock() { Text = text, TextWrapping = inputtb.TextWrapping ,Foreground=inputtb.Foreground,FontFamily=inputtb.FontFamily,FontSize= inputtb.FontSize};
                tb.Tapped += Tb_Tapped;
                canvas.Children.Add(tb);
                Canvas.SetLeft(tb, e.GetPosition(canvas).X);
                Canvas.SetTop(tb, e.GetPosition(canvas).Y);
                Canvas.SetZIndex(tb, 10);
                ismovetext = false;
                return;
            }
            var files = await e.DataView.GetStorageItemsAsync();
            foreach (StorageFile file in files)
            {
                try
                {

                    BitmapImage bi = new BitmapImage();
                    bi.SetSource(await file.OpenAsync(FileAccessMode.Read));
                    IRandomAccessStream irandom = await file.OpenAsync(FileAccessMode.Read);
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(irandom);
                    Image copyimg = new Image() { Width = decoder.PixelWidth, Height = decoder.PixelHeight, Stretch = Stretch.Fill, CanDrag = true };
                    copyimg.Tag = file;
                    copyimg.Holding += Copyimg_Holding;
                    copyimg.DragStarting += Image_DragStartingwithremove;
                    copyimg.IsHoldingEnabled = true;
                    //  copyimg.PointerMoved += Copyimg_PointerMoved;
                    copyimg.Tapped += Copyimg_Tapped;
                  //  copyimg.PointerPressed += Copyimg_PointerPressed; copyimg.PointerReleased += Copyimg_PointerReleased;
                    copyimg.AllowFocusOnInteraction = true;
                    copyimg.Source = bi;
                    if (isremove)
                    {
                        canvas.Children.Remove(removeimg);
                        isremove = false;
                    }
                    int movepixheight = bmp.PixelHeight;
                    int movepixwidth = bmp.PixelWidth;
                    Debug.WriteLine(movepixheight + "movepixheight");
                    Debug.WriteLine(movepixwidth + "movepixwidth");
                    canvas.Children.Add(copyimg);
                    Debug.WriteLine(e.GetPosition(moveimg).X);
                    Debug.WriteLine(e.GetPosition(moveimg).Y);
                    Canvas.SetLeft(copyimg, e.GetPosition(canvas).X);
                    Canvas.SetTop(copyimg, e.GetPosition(canvas).Y);
                    //items.Add(new BitmapItem() { Source = bi });
                }
                catch { }
            }



        }

        private void Tb_Tapped(object sender, TappedRoutedEventArgs e)
        {
            txtpop.Child = new TextoperateControl( canvas, sender as TextBlock);
            txtpop.IsOpen = true;
            txtpop.HorizontalOffset = e.GetPosition(canvas).X + 100;
            txtpop.VerticalOffset = e.GetPosition(canvas).Y + 100;           
        }

        //private async void Copyimg_PointerReleased(object sender, PointerRoutedEventArgs e)
        //{
        //    e.Handled = true;
        //    Debug.WriteLine("Copyimg_PointerReleased");
        //    Debug.WriteLine(e.GetCurrentPoint(canvas).Position.X + "x");
        //    Debug.WriteLine(e.GetCurrentPoint(canvas).Position.Y + "Y");
        //    await Clip_image(presspostion, e.GetCurrentPoint(canvas).Position);
        //    return;
           
        //}

        //private void Copyimg_PointerPressed(object sender, PointerRoutedEventArgs e)
        //{
        //    if (App.isrectange)
        //    {
        //        (sender as Image).CanDrag = false;
        //        presspostion = e.GetCurrentPoint(canvas).Position;
               
        //        Debug.WriteLine("Copyimg_PointerPressed");
        //        Debug.WriteLine(e.GetCurrentPoint(canvas).Position.X + "x");
        //        Debug.WriteLine(e.GetCurrentPoint(canvas).Position.Y + "Y");
        //        e.Handled = true;
        //        return;
        //    }
         
        //}

        private void Copyimg_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (App.isrectange)
            {

            }
            else
            {
                pop.Child = new ImgOperateControl(sender as Image, canvas);
                pop.IsOpen = true;
                pop.HorizontalOffset = e.GetPosition(canvas).X + 100;
                pop.VerticalOffset = e.GetPosition(canvas).Y + 100;
                Debug.WriteLine("Copyimg_Tapped");
                Debug.WriteLine(e.GetPosition(canvas).X + "x");
                Debug.WriteLine(e.GetPosition(canvas).Y + "Y");
            }
        }

        private void Copyimg_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            Debug.WriteLine("Copyimg_PointerMoved");
           // Debug.WriteLine(e.GetCurrentPoint(canvas).Position.X + "x");
           // Debug.WriteLine(e.GetCurrentPoint(canvas).Position.Y + "Y");
        }

        private void Copyimg_Holding(object sender, HoldingRoutedEventArgs e)
        {
            Debug.WriteLine("Copyimg_Holding");
           // Debug.WriteLine(e.GetPosition(canvas).Y + "Y");
        }
        BitmapImage bmp = null;
        Image moveimg = null;
        private async void Image_DragStarting(UIElement sender, DragStartingEventArgs args)
        {
            List<IStorageItem> files = new List<IStorageItem>();
            bmp = (sender as Image).Source as BitmapImage;
            moveimg = (sender as Image);
            StorageFile file = (sender as Image).Tag as StorageFile;
            files.Add(file);
            args.Data.RequestedOperation = DataPackageOperation.Copy;
            args.Data.SetStorageItems(files);
        }
        Image removeimg = null;
        private void Image_DragStartingwithremove(UIElement sender, DragStartingEventArgs args)
        {
            if (App.isrectange)
            {

            }
            else
            {
                isremove = true;
                List<IStorageItem> files = new List<IStorageItem>();
                removeimg = (sender as Image);
                StorageFile file = (sender as Image).Tag as StorageFile;
                //  StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///img/11.jpg"));
                files.Add(file);
                args.DragUI.SetContentFromDataPackage();
                args.Data.RequestedOperation = DataPackageOperation.Copy;
                args.Data.SetStorageItems(files);
            }
        }
        private async void choosepic_click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.FileTypeFilter.Add("*");
            picker.ViewMode = PickerViewMode.List;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            IStorageFile file = await picker.PickSingleFileAsync();
            if (file != null)
            {
                IRandomAccessStream irandom = await file.OpenAsync(FileAccessMode.Read);
                //对图像源使用流源
                BitmapImage bitmapImage = new BitmapImage();
                await bitmapImage.SetSourceAsync(irandom);
                Image img = new Image() { Height = 58,  Margin = new Thickness(12,0,0,0), CanDrag = true,HorizontalAlignment=HorizontalAlignment.Left };
                // img.PointerEntered += Img_PointerEntered;
                img.DragStarting += Image_DragStarting;
                img.Source = bitmapImage;
                img.Tag = file;
                stchoosepic.Children.Add(img);
            }

        }

        private void Img_PointerEntered(object sender, PointerRoutedEventArgs e)
        {

          // Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand,1);
            var t = (sender as Image).TransformToVisual(grid);           
            Point screenCoords = t.TransformPoint(new Point(0, 0));
            double x = screenCoords.X + (sender as Image).Width / 2;
            Debug.WriteLine(x + "x");
            double y = screenCoords.Y + (sender as Image).Height / 2;
            Debug.WriteLine(y + "y");
            Window.Current.CoreWindow.PointerPosition = new Point() { X = x, Y = y };
        }

        private async void Savepic_click(object sender, RoutedEventArgs e)
        {
            if(await SavepictureHelper.SavepicwithUielement(canvas))
            {
                await showmessage("图片保存成功", 3);
            }
            else
            {
                await showmessage("图片保存失败", 3);
            }
        }
        //private async void savepicwithui(UIElement ui)
        //{
        //    string filename = DateTime.Now.ToString("yyyyMMddHHmmss");          
        //    var bitmap = new RenderTargetBitmap();
        //    StorageFile file = await KnownFolders.PicturesLibrary.CreateFileAsync(filename + formmat,
        //        CreationCollisionOption.GenerateUniqueName);
        //    await bitmap.RenderAsync(ui);
        //    var buffer = await bitmap.GetPixelsAsync();
        //    using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
        //    {
        //        var encod = await BitmapEncoder.CreateAsync( BitmapEncoder.JpegEncoderId, stream);
        //        encod.SetPixelData(BitmapPixelFormat.Bgra8,BitmapAlphaMode.Ignore,(uint)bitmap.PixelWidth,(uint)bitmap.PixelHeight,
        //            DisplayInformation.GetForCurrentView().LogicalDpi,DisplayInformation.GetForCurrentView().LogicalDpi,buffer.ToArray());
        //        await encod.FlushAsync();
              

        //    }
        //}
        public async Task showmessage(string str, int i)
        {
            messageborder.Visibility = Visibility.Visible;
            var tb = messageborder.FindName("mtb") as TextBlock;
            tb.Text = str;
            await Task.Delay(TimeSpan.FromSeconds(i));
            messageborder.Visibility = Visibility.Collapsed;

        }

        private async void rectangeSavepic_click(object sender, RoutedEventArgs e)
        {
            App.isrectange = true;
            foreach(var  a in canvas.Children)
            {
                a.CanDrag = false;
            }
            return;
            string filename = DateTime.Now.ToString("yyyyMMddHHmmss");       
            var bitmap = new RenderTargetBitmap();

            StorageFile file = await KnownFolders.PicturesLibrary.CreateFileAsync(filename + formmat,

                CreationCollisionOption.GenerateUniqueName);

            await bitmap.RenderAsync(canvas);

            var buffer = await bitmap.GetPixelsAsync();

            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))

            {

                var encod = await BitmapEncoder.CreateAsync(

                    BitmapEncoder.JpegEncoderId, stream);

                encod.SetPixelData(BitmapPixelFormat.Bgra8,

                    BitmapAlphaMode.Ignore,

                    (uint)bitmap.PixelWidth,

                    (uint)bitmap.PixelHeight,

                    DisplayInformation.GetForCurrentView().LogicalDpi,

                    DisplayInformation.GetForCurrentView().LogicalDpi,

                    buffer.ToArray()

                   );

                await encod.FlushAsync();


            }
            //文件处理  
            if (file != null)
            {

                var inputFile = SharedStorageAccessManager.AddFile(file);
                var destination = await KnownFolders.PicturesLibrary.CreateFileAsync("Cropped.jpg", CreationCollisionOption.ReplaceExisting);//在应用文件夹中建立文件用来存储裁剪后的图像  
                var destinationFile = SharedStorageAccessManager.AddFile(destination);
                var options = new LauncherOptions();
                options.TargetApplicationPackageFamilyName = "Microsoft.Windows.Photos_8wekyb3d8bbwe";

                //待会要传入的参数  
                var parameters = new ValueSet();
                parameters.Add("InputToken", inputFile);                //输入文件  
                parameters.Add("DestinationToken", destinationFile);    //输出文件  
                parameters.Add("ShowCamera", false);                    //它允许我们显示一个按钮，以允许用户采取当场图象(但是好像并没有什么卵用)  
                parameters.Add("EllipticalCrop", true);                 //截图区域显示为圆（最后截出来还是方形）  
                parameters.Add("CropWidthPixals", 300);
                parameters.Add("CropHeightPixals", 300);

                //调用系统自带截图并返回结果  
                var result = await Launcher.LaunchUriForResultsAsync(new Uri("microsoft.windows.photos.crop:"), options, parameters);

                //按理说下面这个判断应该没问题呀，但是如果裁剪界面点了取消的话后面会出现异常，所以后面我加了try catch  
                if (result.Status == LaunchUriStatus.Success && result.Result != null)
                {
                    //对裁剪后图像的下一步处理  
                    await showmessage("图片裁剪成功", 3);
                }
            }
        }
        Point presspostion;
        private void canvas_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            //if(e.OriginalSource is Image)
            //{
            //    (e.OriginalSource as Image).CanDrag = false;
        

            //}
            Debug.WriteLine("canvas_PointerPressed");
            presspostion = e.GetCurrentPoint(canvas).Position;
        }



        private async void canvas_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            if (App.isrectange)
            {
                string filename = DateTime.Now.ToString("yyyyMMddHHmmss");              
                var bitmap = new RenderTargetBitmap();
                StorageFile file = await KnownFolders.PicturesLibrary.CreateFileAsync(filename + formmat,CreationCollisionOption.GenerateUniqueName);
                await bitmap.RenderAsync(canvas);
                var buffer = await bitmap.GetPixelsAsync();
                using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encod = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
                    encod.SetPixelData(BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Ignore,
                        (uint)bitmap.PixelWidth,
                        (uint)bitmap.PixelHeight,
                        DisplayInformation.GetForCurrentView().LogicalDpi,
                        DisplayInformation.GetForCurrentView().LogicalDpi,
                        buffer.ToArray());
                    await encod.FlushAsync();
                }
                StorageFile newfile = await KnownFolders.PicturesLibrary.CreateFileAsync(filename +"clip_"+ formmat,
                CreationCollisionOption.GenerateUniqueName);
                Point releasepostion = e.GetCurrentPoint(canvas).Position;
                double width = releasepostion.X - presspostion.X;
                double height = releasepostion.Y - presspostion.Y;
                Rectangle rec = new Rectangle();
                rec.Width =Math.Abs(width);
                rec.Height = Math.Abs(height);
                rec.Stroke = new SolidColorBrush(Colors.Red);
                Size size = new Size() { Width =Math.Abs(width), Height = Math.Abs(height) };
                canvas.Children.Add(rec);
                Canvas.SetLeft(rec, presspostion.X);
                Canvas.SetTop(rec, presspostion.Y);
                await BitmapHelper.SaveCroppedBitmapAsync(file, newfile, presspostion, size);
                await showmessage("图片保存成功",2);
                App.isrectange = false;
                canvas.Children.Remove(rec);
            }
        }
        private async Task Clip_image(Point releasepostion,Point presspostion)
        {
            string filename = DateTime.Now.ToString("yyyyMMddHHmmss");
            var bitmap = new RenderTargetBitmap();
            StorageFile file = await KnownFolders.PicturesLibrary.CreateFileAsync(filename + formmat, CreationCollisionOption.GenerateUniqueName);
            await bitmap.RenderAsync(canvas);
            var buffer = await bitmap.GetPixelsAsync();
            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                var encod = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
                encod.SetPixelData(BitmapPixelFormat.Bgra8,
                    BitmapAlphaMode.Ignore,
                    (uint)bitmap.PixelWidth,
                    (uint)bitmap.PixelHeight,
                    DisplayInformation.GetForCurrentView().LogicalDpi,
                    DisplayInformation.GetForCurrentView().LogicalDpi,
                    buffer.ToArray());
                await encod.FlushAsync();
            }
            StorageFile newfile = await KnownFolders.PicturesLibrary.CreateFileAsync(filename + "clip_" + formmat,
            CreationCollisionOption.GenerateUniqueName);         
            double width = releasepostion.X - presspostion.X;
            double height = releasepostion.Y - presspostion.Y;
            Rectangle rec = new Rectangle();
            rec.Width = width;
            rec.Height = height;
            rec.Stroke = new SolidColorBrush(Colors.Red);
            Size size = new Size() { Width = width, Height = height };
            canvas.Children.Add(rec);
            Canvas.SetLeft(rec, presspostion.X);
            Canvas.SetTop(rec, presspostion.Y);
            await BitmapHelper.SaveCroppedBitmapAsync(file, newfile, presspostion, size);
            await showmessage("图片保存成功", 2);
            canvas.Children.Remove(rec);
        }
        private async void setbackgroudimgpic_click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.FileTypeFilter.Add("*");
            picker.ViewMode = PickerViewMode.List;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            IStorageFile file = await picker.PickSingleFileAsync();
            if (file != null)
            {
                IRandomAccessStream irandom = await file.OpenAsync(FileAccessMode.Read);
                //对图像源使用流源
                BitmapImage bitmapImage = new BitmapImage();
                await bitmapImage.SetSourceAsync(irandom);
                canvas.Background = new ImageBrush() { ImageSource = bitmapImage };
            }
        }

        private void UWPColorPickerControl_ColorSelected(object sender, Color color)
        {
            colorFlyout.Hide();
            canvas.Background = new SolidColorBrush(color);
        }
        bool ismovetext = false;
        private void textdarging(UIElement sender, DragStartingEventArgs args)
        {
            args.Data.RequestedOperation = DataPackageOperation.Copy;
            args.Data.SetText((sender as TextBlock).Text);
            ismovetext = true;
        }

        private void clear_click(object sender, RoutedEventArgs e)
        {
            //var uilist = canvas.Children;
            canvas.Children.Clear();
            //foreach (var a in uilist)
            //{
            //    canvas.Children.Remove(a);
            //}
        }
        Frame frame; int newViewId; bool viewShown;
        private async void mulitipic_click(object sender, RoutedEventArgs e)
        {



            FileOpenPicker picker = new FileOpenPicker();
            picker.FileTypeFilter.Add("*");
            picker.ViewMode = PickerViewMode.List;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            var file = await picker.PickMultipleFilesAsync();
            if (file != null)
            {
                // this.Frame.Navigate(typeof(ManagerFolderPicturePage), file);
                CoreApplicationView newView = CoreApplication.CreateNewView();
                await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var newWindow = Window.Current;
                    var newAppView = ApplicationView.GetForCurrentView();
                    frame = new Frame();
                    frame.Navigate(typeof(ManagerFolderPicturePage), file);
                    newWindow.Content = frame;
                    newWindow.Activate();
                    newViewId = newAppView.Id;
                });
                viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
            }
        }

        private void mulititext_checked(object sender, RoutedEventArgs e)
        {
            inputtb.TextWrapping = TextWrapping.Wrap;
        }

        private void mulititext_unchecked(object sender, RoutedEventArgs e)
        {
            inputtb.TextWrapping = TextWrapping.NoWrap;
        }
        public void getFontList()
        {
            List<FontFamily> fList = new List<FontFamily>();

            string[] fontList = Microsoft.Graphics.Canvas.Text.CanvasTextFormat.GetSystemFontFamilies();
            foreach (var font in fontList)
            {
                fList.Add(new FontFamily(font));
            }
            FontListBox.ItemsSource = fList;
        }
        public ObservableCollection<NamedColor> Colorslist = new ObservableCollection<NamedColor>();
        private void Getcolorlist()
        {
            foreach (var color in typeof(Colors).GetRuntimeProperties())
            {
                Colorslist.Add(new NamedColor() { Name = color.Name, Color = (Color)color.GetValue(null) });
            }
            Colorslistbox.ItemsSource = Colorslist;

        }

        private void Colorslistbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            NamedColor selectedcolor = (Colorslistbox.SelectedItem as NamedColor);
            inputtb.Foreground = new SolidColorBrush(selectedcolor.Color);
        }

        private void FontListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            FontFamily selectedfont = (FontListBox.SelectedItem as FontFamily);
            inputtb.FontFamily = FontFamily;
           
        }

        private void FontsizeListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            inputtb.FontSize = (double)FontsizeListBox.SelectedItem;
        }

        private async void about_click(object sender, RoutedEventArgs e)
        {
            int newViewId2=0;
            CoreApplicationView newView = CoreApplication.CreateNewView();
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var newWindow = Window.Current;
                var newAppView = ApplicationView.GetForCurrentView();
                Frame frame = new Frame();
                frame.Navigate(typeof(AboutPage));
                newWindow.Content = frame;
                newWindow.Activate();
                newViewId2 = newAppView.Id;
            });
           bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId2);
        }

        private async void singlepic_opreateclick(object sender, RoutedEventArgs e)
        {
            int newViewId2 = 0;
            CoreApplicationView newView = CoreApplication.CreateNewView();
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var newWindow = Window.Current;
                var newAppView = ApplicationView.GetForCurrentView();
                Frame frame = new Frame();
                frame.Navigate(typeof(ImageToolPage));
                newWindow.Content = frame;
                newWindow.Activate();
                newViewId2 = newAppView.Id;
            });
            bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId2);
        }

        private async void singlepic_effectsclick(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.FileTypeFilter.Add("*");
            picker.ViewMode = PickerViewMode.List;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            var file = await picker.PickSingleFileAsync();
            if (file != null)
            {
                // this.Frame.Navigate(typeof(ManagerFolderPicturePage), file);
                CoreApplicationView newView = CoreApplication.CreateNewView();
                await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var newWindow = Window.Current;
                    var newAppView = ApplicationView.GetForCurrentView();
                    frame = new Frame();
                    frame.Navigate(typeof(Lumiaimagepage), file);
                    newWindow.Content = frame;
                    newWindow.Activate();
                    newViewId = newAppView.Id;
                });
                viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
            }
        }
    }

    public class NamedColor
    {
        public string Name { get; set; }
        public Color Color { get; set; }
    }

}
